package com.itzjc.controller;

import com.itzjc.domain.entity.*;
import com.itzjc.domain.pojo.All3DGraphData;
import com.itzjc.domain.pojo.AllCurrentData;
import com.itzjc.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * TODO
 *
 * @className: DataController
 * @date: 2021-06-28 20:30
 **/
@RestController
@RequestMapping("/web/api/v1/pri/data")
public class DataController {
    @Autowired
    private DataService dataService;

    @GetMapping("/getAllInitDataByToken")
    public Result getAllInitDataByToken(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
        List<TableData> projectInfoList = dataService.getAllInitDataByToken();
        return Result.buildSuccess("获取列表成功", projectInfoList);

    }
    @GetMapping("/getBaseInfoByToken")
    public Result getBaseInfoByToken(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
      TableBaseInfo tableBaseInfo = dataService.getBaseInfoByToken();
        return Result.buildSuccess("获取信息成功",tableBaseInfo);
    }

    @GetMapping("/gettableTitleByToke")
    public Result gettableTitleByToke(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
        TitleInfo titleInfo = dataService.gettableTitleByToke();
        return Result.buildSuccess("获取信息成功",titleInfo);
    }
    @GetMapping("/getAllGraphDataByToken")
    public Result getAllGraphDataByToken(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
        List<PlaneData> AllGraphData=dataService.getAllGraphDataByToken();
        if (AllGraphData.size()>0) {
            return Result.buildSuccess("获取信息成功",AllGraphData);
        }
        return Result.buildError("传感器数据没有更新",300);
    }

    @GetMapping("/getAll3DGraphDataByToken")
    public Result getAll3DGraphDataByToken(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
        List All3DGraphData=dataService.getAll3DGraphDataByToken();
        if (All3DGraphData.size()>0) {
            return Result.buildSuccess("获取信息成功",All3DGraphData);
        }
        return Result.buildError("传感器数据没有更新",300);
    }

    @GetMapping("/getAllPredictDataByToken")
    public Result getAllPredictDataByToken(HttpServletRequest request){
        Integer userId = (Integer) request.getAttribute("user_id");
        if (null == userId) {
            return Result.buildError("用户没有登录", 300);
        }
        List AllPredictData=dataService.getAllPredictDataByToken();
        if (AllPredictData.size()>0) {
            return Result.buildSuccess("获取信息成功",AllPredictData);
        }
        return Result.buildError("传感器数据没有更新",300);
    }

}
